How can I find a URL called [link] inside a block of HTML containing other URLs?

Posted by DrTwox on Stack Overflow See other posts from Stack Overflow or by DrTwox
Published on 2014-05-28T02:22:30Z Indexed on 2014/05/28 3:25 UTC
Read the original article Hit count: 136

Filed under:

I'm writing a script to rewrite Reddit's RSS feeds. The script needs to find a URL named [link] inside a block of HTML that contains other URLs. The HTML is contained in an XML element called <description>.

Here are two examples of the <description> element from I need to parse and the [link] I would need to get.


First example:

<description>submitted by &lt;a href=&#34;http://www.reddit.com/user/wildlyinaccurate&#34;&gt; wildlyinaccurate &lt;/a&gt; &lt;br/&gt; &lt;a href=&#34;http://wildlyinaccurate.com/a-hackers-guide-to-git&#34;&gt;[link]&lt;/a&gt; &lt;a href="http://www.reddit.com/r/programming/comments/26jvl7/a_hackers_guide_to_git/"&gt;[66 comments]&lt;/a&gt;</description>

The [link] is: http://wildlyinaccurate.com/a-hackers-guide-to-git


Second example:

<description>&lt;!-- SC_OFF --&gt;&lt;div class=&#34;md&#34;&gt;&lt;p&gt;I work a support role at a company where I primarily fix issues our customers our experiencing with our software, which is a browser based application written primarily in javascript. I&amp;#39;ve been doing this for 2 years, but I want to take it to the next level (with the long term goal being that I become proficient enough to call myself a developer). I&amp;#39;ve been reading &amp;quot;Javascript The Definitive Guide&amp;quot; by O&amp;#39;Reilly but I was wondering if any of you more experienced users out there had some tips on taking it to the next level. Should I start incorporating some PHP and Jquery into my learning? Side projects on my spare time? Any good online resources? Etc. &lt;/p&gt; &lt;p&gt;Thanks! &lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; submitted by &lt;a href=&#34;http://www.reddit.com/user/56killa&#34;&gt; 56killa &lt;/a&gt; &lt;br/&gt; &lt;a href=&#34;http://www.reddit.com/r/javascript/comments/26nduc/i_want_to_become_more_experienced_with_javascript/&#34;&gt;[link]&lt;/a&gt; &lt;a href="http://www.reddit.com/r/javascript/comments/26nduc/i_want_to_become_more_experienced_with_javascript/"&gt;[4 comments]&lt;/a&gt;</description>

The [link] is: http://www.reddit.com/r/javascript/comments/26nduc/i_want_to_become_more_experienced_with_javascript/


© Stack Overflow or respective owner

Related posts about google-apps-script